package com.atguigu.springcloud;

import com.atguigu.springcloud.service.PaymentFeignService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author csc
 * @Date 2023/3/18 0018 15:23
 * @Version 1.0
 */
@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_global_fallbackMethod")
public class OrderHystrixController
{

    @Resource
    private PaymentFeignService paymentFeignService;


    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id){
        String result = paymentFeignService.paymentInfo_OK(id);
        log.info("*********result:"+result);
        return result;
    }


    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
  /*  @HystrixCommand(fallbackMethod = "paymentInfo_TimeOutHandler",commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1500")
    })*/
    @HystrixCommand
    public String paymentInfo_Timeout(@PathVariable("id") Integer id){
        String result = paymentFeignService.paymentInfo_Timeout(id);
        log.info("*********result:"+result);
        return result;
    }

    public String paymentInfo_TimeOutHandler(Integer id){
        return "hystrix服务降级生效了.还调用呢.别调用了回家玩去吧";
    }//end



   public String payment_global_fallbackMethod(){

        return "Global全局异常处理信息,请稍后重试,";
   }//end
}
